
-- a stored procedure to add new notification
-- return 1 if can add, 0 cannot add (it already exists)
IF OBJECT_ID('addNotification') IS NOT NULL
BEGIN
	DROP PROCEDURE addNotification;
END
GO

CREATE PROCEDURE addNotification
@toolId		VARCHAR(120),
@houseId	INT,
@when		VARCHAR(5),
@userId		INT,
@isSms		VARCHAR(5),
@isAlarm	VARCHAR(5),
@startTime	VARCHAR(30),
@endTime	VARCHAR(30)
AS
BEGIN
	SET NOCOUNT ON
	IF NOT EXISTS(SELECT * FROM [notification] WHERE toolid=@toolId and whentonotify=@when )
	BEGIN
		INSERT INTO [notification](toolid, houseid,whentonotify,userid,issms,isalarm,starttime,endtime)
		VALUES(@toolId,@houseId,@when,@userId,@isSms,@isAlarm,@startTime,@endTime);
		SELECT 1;
	END
	ELSE
	BEGIN
		SELECT 0;
	END
END
GO
